package com.kotlin.myapplication.mvp.widget;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kotlin.myapplication.R;


/**
 * 自定义引导页View
 * @author zhazb
 *
 */
@SuppressLint("InflateParams")
public class LeadPageView extends LinearLayout{
	
	private Context context;
	private TextView title;
	private TextView content;
	private ImageView image;
	private Button button;
	private TextView skip;
	private TextView centertext;
	private TextView up;
	private TextView mid;
	private TextView down;
	private View midlayout;

	public LeadPageView(Context context) {
		super(context);
		this.context = context;
		initView();
	}

	private void initView() {
		View convertView = LayoutInflater.from(context).inflate(R.layout.view_lead_page, this);
		title = (TextView) convertView.findViewById(R.id.lead_page_title);
		content = (TextView) convertView.findViewById(R.id.lead_page_content);
		image = (ImageView) convertView.findViewById(R.id.lead_page_image);
		button = (Button) convertView.findViewById(R.id.lead_page_button);
		skip = (TextView) convertView.findViewById(R.id.lead_page_skip);
		centertext = (TextView) convertView.findViewById(R.id.centertext);
		up = (TextView) convertView.findViewById(R.id.up);
		mid = (TextView) convertView.findViewById(R.id.mid);
		down = (TextView) convertView.findViewById(R.id.down);
		midlayout = convertView.findViewById(R.id.midlayout);

	}
	
	
	/**
	 * set leadpage title
	 * @param title
	 */
	public void setLeadPageTitle(String title) {
		if (this.title != null) {
			this.title.setText(title);
		}
	}
	
	/**
	 * set leadpage content
	 * @param content
	 */
	public void setLeadPageContent(String content) {
		if (this.content != null) {
			this.content.setText(content);
		}
	}
	
	/**
	 * set leadpage icon resource
	 * @param resource
	 */
	public void setLeadPageIconResource(int resource) {
		if (this.image != null) {
			this.image.setBackgroundResource(resource);
		}
	}
	
	/**
	 * set leadpage operate button visible
	 * @param isVisible
	 */
	public void setLeadPageOperateButtonVisible(boolean isVisible, String content) {
		if (this.button != null) {
			this.button.setVisibility(isVisible ? View.VISIBLE : View.GONE);
			this.button.setText(content);
		}
	}
	
	/**
	 * set leadpage operate button clicklistener
	 * @param listener
	 */
	public void setLeadPageOperateButtonOnClickListener(OnClickListener listener) {
		if (this.button != null) {
			this.button.setOnClickListener(listener);
		}
	}

	/**
	 * set leadpage skip button clicklistener
	 * @param listener
	 */
	public void setLeadPageSkipButtonOnClickListener(OnClickListener listener) {
		if (this.skip != null) {
			this.skip.setOnClickListener(listener);
		}
	}

	public void setLeadPageSkipButtonVisible(boolean visible){
		if(visible) {
			this.skip.setVisibility(VISIBLE);
		}else {
			this.skip.setVisibility(GONE);
		}
	}

	public TextView getCenterTextView(){
		return centertext;
	}
	public TextView getMidTextView(){
		return mid;
	}
	public TextView getDownTextView(){
		return down;
	}
	public void clearTextView(){
		centertext.setText("");
		up.setText("");
		mid.setText("");
		down.setText("");
	}

	public void setCenterText(String content){
		if(null != content && !content.isEmpty()){
			centertext.setText(content);
		}
	}
	public void setUpText(String content){
		if(null != content && !content.isEmpty()){
			up.setText(content);
		}
	}
	public void setMidText(String content){
		if(null != content && !content.isEmpty()){
			mid.setText(content);
		}
	}
	public void setDownText(String content){
		if(null != content && !content.isEmpty()){
			down.setText(content);
		}
	}
	
}
